<?php
/**
 * 发票管理model
 * author:ty
 * date:2017/08/30
 */
namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Invoice extends Model
{
    protected $table='invoice';

    /**
     * 发票列表
     * @param 查询条件
     */
    public static function lists($param)
    {
        $res = DB::table('invoice')
            ->where('invoice_status',$param['status'])
            ->where('invoice_isdel',$param['isdel'])
            ->paginate($param['pagesize']);
        return $res;
    }

    /**
     * 已开发票列表
     * @param查询参数数组
     */
    public static function invoice_used($param)
    {
        $res = DB::table('invoice')
            ->leftJoin('address','address.addr_id','=','invoice.invoice_address_id')
            ->where('invoice_status','>',1)
            ->where('invoice_user_id',$param['userid'])
            ->select('invoice.*','address.addr_area','address.addr_city','address.addr_town','address.addr_detail','address.addr_rephone','address.addr_rename')
            ->paginate($param['pagesize']);
        return $res;
    }
}
